// Copyright (c) 2023, zongying_cao@163.com
// All rights reserved.
//
// This software is licensed under the MIT License.
struct MyStruct {
    name: String,
}

fn use_struct(my_struct: &MyStruct) {
    println!("use_struct my_struct.name:{}", my_struct.name);
}

fn about_struct() {
    let my_struct = MyStruct {
        name: "Alan".to_string(),
    };
    use_struct(&my_struct);
    println!("my_struct.name:{}", my_struct.name);
}

fn to_pointer(val: Option<&u32>) -> *const u32 {
    match val {
        None => std::ptr::null(),
        Some(value) => value as *const u32,
    }
}
fn about_pointer() {
    unsafe {
        let val: *const u32 = to_pointer(None);
        println!("val:{}", *val);
    }
}
fn main() {
    about_struct();
    about_pointer();
}

/*
 * 演示所有权转移的编译报错
struct MyStruct {
    name: String,
}
fn use_struct(my_struct: MyStruct) {
    println!("use_struct my_struct.name:{}", my_struct.name);
}

fn about_struct() {
    let my_struct = MyStruct {
        name: "Alan".to_string(),
    };
    use_struct(my_struct);
    println!("my_struct.name:{}", my_struct.name);
}
fn main() {
    about_struct();
}
*/
